<!DOCTYPE html>
<meta charset="utf-8" />
<link rel="stylesheet" href="ace_v1.3/assets/css/ui.jqgrid.css" />


<div class="search_panel">
<form action="" method="post" onsubmit="return pageSearch(this);">
	<div style="display: block;" class="widget-body ">
		<div class="widget-main">
			<div class="rowt">
				<div class="col-sm-12">
					<div>
						<!--  
							<div class="table-from">
							<input id="userId" name="userId" class="search-input" type="text" autocomplete="off" placeholder="操作员账号 ...">
							<i class="ace-icon fa fa-search glyphicon-search"></i>
							</div>-->
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">商户名称:</label>
							<div class="search_input">
								<input id="custName" type="text" name="custName"
									placeholder="请输入商户名称">
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">商户编号:</label>
							<div class="search_input">
								<input id="custId" type="text" name="custId"
									placeholder="请输入商户编号">
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">商户手机:</label>
							<div class="search_input">
								<input id="usrMobile" type="text" name="usrMobile"
									placeholder="请输入商户手机">
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">证件号码:</label>
							<div class="search_input">
								<input id="certificateNo" type="text" name="certificateNo"
									placeholder="请输入证件号码">
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px;margin-right: 15px;width: 280px;">
						    <label class="label_search" for="userName">注册日期:</label>
							<div class="input-group">
								<input type="text" class="form-control date-picker" name="startTime" data-date-format="yyyy-mm-dd" placeholder="起始日期" />
								<span class="input-group-addon">
									<i class="fa fa-exchange"></i>
								</span>
								<input type="text" class="form-control date-picker" name="endTime" data-date-format="yyyy-mm-dd" placeholder="结束日期" />
							</div>

							<!-- /section:plugins/date-time.datepicker -->
						</div>
						<div class="search_elm" style="margin-left: 0px;width: 200px">
							<label class="label_search" for="userName">认证状态:</label>
							<div class="search_input">
							    <select 
									 rel="obj.CUSTSTATUS"
						 			 location="local" 
									 name="custStatus" 
						 			id="custStatus" 
						 			data-placeholder="请选择状态" style="width: 120px;vertical-align:middle;">
							<option value='' >--请选择--</option>
						 </select>
							
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px;width: 300px">
							<label class="label_search" for="userName">公安部身份认证状态:</label>
							<div class="search_input">
							    <select 
									 rel="obj.POLICEIDENTIFYSTATUS"
						 			 location="local" 
									 name="policeIdentifystatus" 
						 			id="policeIdentifystatus" 
						 			data-placeholder="请选择状态" style="width: 120px;vertical-align:middle;">
							<option value='' >--请选择--</option>
						 </select>
							
							</div>
						</div>
						
						<div class="search_button">
							<button class="btn btn-small btn_search" type="submit" title="搜索" >
								搜索
							</button>
							
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	</form>
</div>
	<div class="row">
		<div class="col-xs-12">
			<table id="grid-table"></table>

			<div id="grid-pager"></div>

			<div style="margin-top: 10px">
				<span id="auth_btn">
				<a class="btn btn-small btn-info"
					onclick="report();"> <!-- 
					<i class="icon-envelope"></i> -->生成文件
				</a>				
				
				</span> <span id="paging_bar" style="float: right"> </span>
			</div>

			<!-- PAGE CONTENT ENDS -->
		</div>
		<!-- /.col -->
	</div>
	<!-- /.row -->

	<!-- page specific plugin scripts -->
	<script type="text/javascript">
		var jqGrid;
		jQuery(function($) {
			var grid_selector = "#grid-table";
			var pager_selector = "#grid-pager";

			$(window).on(
					'resize.jqGrid',
					function() {
						$(grid_selector).jqGrid('setGridWidth',
								$(".page-content").width());
					})
			var parent_column = $(grid_selector).closest('[class*="col-"]');
			$(document).on(
					'settings.ace.jqGrid',
					function(ev, event_name, collapsed) {
						if (event_name === 'sidebar_collapsed'
								|| event_name === 'main_container_fixed') {
							setTimeout(function() {
								$(grid_selector).jqGrid('setGridWidth',
										parent_column.width());
							}, 0);
						}
					})
			jQuery(grid_selector).jqGrid({
				url : "mpomng/meridentifyManage/query.do",
				datatype : "json",
				height : '100%',
				width : '100%',
				colNames : [ '商户名称', '商户编号','营业名称','商户手机号','证件类型', '证件号码','认证状态','注册时间','认证时间','审核人', '公安部身份认证状态','操作' ],
				colModel : [ {name : 'custName',     index : 'custName',     width : '100px' }, 
				             {name : 'custId',       index : 'custId',       width : '150px' }, 
				             {name : 'custMerName',       index : 'custMerName',       width : '150px' }, 
				             {name : 'usrMobile',       index : 'usrMobile',       width : '150px' }, 
				             {name : 'certificateType',     index : 'certificateType',     width : '80px' , ditcKey:'CERTTYPE', formatter : gridFormatByDict},
				             {name : 'certificateNo',    index : 'certificateNo',    width : '200px' }, 
				             {name : 'custStatus',   index : 'custStatus',   width : '100px' ,ditcKey:'CUSTSTATUS' ,formatter : gridFormatByDict}, 
				             {name : 'custRegDatetime',  index : 'custRegDatetime',   width : '150px',formatter : gridFormatByDate}, 
				             {name : 'identifyTime',  index : 'identifyTime',   width : '150px',formatter : gridFormatByDate}, 
				             {name : 'identifyUser',   index : 'identifyUser',   width : '100px' }, 
				             {name : 'policeIdentifystatus',         index : 'policeIdentifystatus', width : '125px' ,ditcKey:'POLICEIDENTIFYSTATUS' ,formatter : gridFormatByDict}, 
				             {name : 'op',  index : 'op',  width : '130px' ,formatter:operateEdit}
				            ],
				viewrecords : true,
				rowNum : 10,
				rowList : [ 10, 20, 30 ],
				altRows : true,

				multiselect : true,//设置行可多选的 
				multiboxonly : true,//
				shrinkToFit:false,
				loadComplete : function() {
					var table = this;
					setTimeout(function() {
						//加载分页
						initPagingBar(grid_selector);
					}, 0);
				},
				beforeRequest : function() {//请求之前执行
					jqGrid = this;
				},
			});
			$(window).triggerHandler('resize.jqGrid');

			$(document).one('ajaxloadstart.page', function(e) {
				$(grid_selector).jqGrid('GridUnload');
				$('.ui-jqdialog').remove();
			});

			function operateEdit(cellvalue, options, rowObject){// "<div class='hidden-phone visible-desktop btn-group'>"
				var button = "<div class=\"hidden-sm hidden-xs btn-group\">";  //定义button
					button += "<button class='btn btn-xs btn-warning' onclick='selectMeridentify(\""+rowObject["custId"]+"\",\"view\")'" 
					+"title='详细信息查看'>详细</button>";
					if(rowObject["custStatus"]==1||rowObject["custStatus"]==0){
						button += "<button class='btn btn-xs btn-warning' onclick='selectMeridentify(\""+rowObject["custId"]+"\",\"audit\")'" 
						+"title='详细信息查看'>审核</button>";
					}
					button += "<button class='btn btn-xs btn-warning' onclick='setMerName(\""+rowObject["custId"]+"\",\""+rowObject["custMerName"]+"\")'" 
					+"title='编辑收款商户名称'>编辑</button>";
				return button;
			}
			//格式化日期
			function dateFormat(cellvalue, options, rowObject){
				return getDateFormat(rowObject["identifyTime"]);
			}
		});

		function selectMeridentify(custId,type) {
			if(custId.length<=0){
				msg.alert("警告", "当前没有选择数据项！", "error");
				return;
			}
			var scrWidth = document.body.scrollWidth;
			openDialog({
				dialogId : 'dlg-agentEdit',
				title : '商户实名认证信息详情',
				pageUrl :'mpomng/meridentifyManage/view.do',
				dataUrl : 'mpomng/meridentifyManage/queryById.do',
				width : '80%',
				height:'80%',
				dataParam : {
					custId : custId,
					type:type
				},
				dataName : 'obj,map'//表单数据存储对象名称

			});
		}
		//编辑用户
		function useredit() {
			var rows = $('#grid-table').jqGrid("getGridParam", "selarrrow");
			
			if (rows.length == 0) {
				msg.alert("警告", "当前没有选择数据项！", "error");
				return;
			}
			if (rows.length > 1) {
				msg.alert("警告", "不能同时选择多项数据！", "warn");
				return;
			}
			if(rows[0] == UID._USER_NO){
				msg.alert("警告", "系统超级用户不能被修改！", "warn");
				return ;
			}
			openDialog({
				dialogId : 'dlg-useredit',
				title : '编辑用户',
				pageUrl : 'auth/userManage/editView.do',
				dataUrl : 'auth/userManage/queryUserById.do',
				width :'60%',
				height:'40%',
				dataParam : {
					id : rows[0]
				},
				dataName : 'obj' //表单数据存储对象名称

			});
		}
		//用户删除
		function userdelete() {
			var rows = $('#grid-table').jqGrid("getGridParam", "selarrrow");
			if (rows.length == 0) {
				msg.alert("警告", "当前没有选择数据项！", "warn");
				return;
			}

			//
			var ids = "";
			for (var i = 0; i < rows.length; i++) {
				if (rows[i] == UID.id) {
					msg.alert("警告", "无法删除自己 ！", "warn");
					return;
				}
				ids = ids + rows[i] + ",";
			}
			ids = ids.substring(0, ids.lastIndexOf(","));
			msg.confirm({title:'确认',position:'center',msg:'您确定要删除选中的数据吗？',call:function(ok){
				if(ok){
					$.ajax({
						type : "post",
						url : "auth/userManage/delete.do?userId=" + ids,
						dataType : 'json',
						success : function(result) {
							if (result.rspcod != 200) {
								msg.alert("错误", result.rspmsg + " 错误代码："
										+ result.rspcod, 'error');
							} else {
								msg.alert("提示", result.rspmsg, 'correct');
								$("#grid-table").trigger("reloadGrid");
							}
						},
						error : function(XMLHttpRequest, textStatus) {
							msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："
									+ textStatus, 'error');
						}
					});

				}
			}});
			
			}
		
			
	    function statusUpdate0(){
	    	setUserStatus(0);
	    }
	    function statusUpdate1(){
	    	setUserStatus(1);
	    }
		function setUserStatus(status){
			var rows = $('#grid-table').jqGrid("getGridParam", "selarrrow");
			if (rows.length == 0) {
				msg.alert("警告", "当前没有选择的数据项,请选择数据！", "warn");
				return;
			}
			
			var ids="",uname="";
			var rowData ;
			for(var i=0; i<rows.length; i++){
				rowData = $('#grid-table').jqGrid('getRowData',rows[i]);
				if(rowData.id == UID._USER_NO){
					msg.alert("警告", "超级管理员信息不能被修改！", "warn");
					return ;
				}
				if(rowData.id == UID.id){
					msg.alert("警告", "不能修改当前正在使用的用户！", "warn");
					return ;
				}
				ids   = ids+rowData.id+",";
				uname = uname + rowData.userName+",";
			}
			ids   = ids.substring(0, ids.lastIndexOf(","));
			uname = uname.substring(0, uname.lastIndexOf(","));
			var tmsg = "启用";
			if(status == 1){
				tmsg = "禁用";
			}
			
			msg.confirm({title:'确认',position:'center',msg:'您确定要'+tmsg+'操作员['+uname+']吗？',call:function(ok){
				if(ok){
					$.ajax({
						type : "post",
					    url : "auth/userManage/modifyUsersStatus.do?status="+status+"&userId="+ids,
						dataType : 'json',
						success : function(result) {
							if (result.rspcod != 200) {
								msg.alert("错误", result.rspmsg + " 错误代码："
										+ result.rspcod, 'error');
							} else {
								msg.alert("提示", result.rspmsg, 'correct');
								$("#grid-table").trigger("reloadGrid");
							}
						},
						error : function(XMLHttpRequest, textStatus) {
							msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："
									+ textStatus, 'error');
						}
					});

				}
			}});
			
		}
		
	function submitUpdate(){
		validateCallback($("#updateForm"),dialogAjaxDone);
		return false;
	}
		
	function setMerName(custId,custMerName){
		var html = '';
		html += '<br/><form id="updateForm" class="form-horizontal" role="form"  onsubmit="return submitUpdate(this);" method="post" action="mpomng/meridentifyManage/updateMer.do">'
			+ '<div class="form-group">'
			+	'<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 商户编号： </label>'
			+	'<div class="col-sm-9">'
			+			'<input type="text" name="custId" value="'+custId+'" placeholder="请输入[商户编号]" readonly="readonly" validate="true"  class="col-xs-10 col-sm-7"  datatype="bankcard" />'
			+	'</div>'
			+'</div>'
			+'<div class="form-group">'
			+	'<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 营业名称： </label>'
			+		'<div class="col-sm-9">'
			+			  '<input type="text" name="custMerName" value="'+(custMerName||'')+'" placeholder="请输入[商户收款名称]" class="col-xs-10 col-sm-7"  datatype="bankcard" />'
			+	    '</div>'
			+'</div>'
	   		+'<div class="form-actions align-right  form-button-box" style="margin-top: 10px"><button class="btn btn-info" type="submit">保存</button>'
		    +'&nbsp; <button class="btn" type="button" onclick="javascript:dialog.close(this);"> 关闭</button>'
		    +'</div>'
			+ '</form>';
		    openDialog({
			dialogId : 'dlg-setMerName',
			title : '编辑用户',
			width :'60%',
			height:'40%',
			html : html
		});
	}
		
	function report(){
		var sdate = "00000000";
		var edate = "99999999";
		var param = "";
		
		msg.confirm({title:'确认',position:'center',msg:'确认导出当前数据吗？',call:function(ok){
			if(ok){
				$.ajax({
					type : "post",
				    url : "mpomng/mobileMerManage/report.do?"+param,
					dataType : 'json',
					success : function(result) {
						if (result.rspcod != 200) {
							msg.alert("错误", result.rspmsg + " 错误代码："
									+ result.rspcod, 'error');
						} else {
							msg.alert("提示", result.rspmsg, 'correct');
						}
					},
					error : function(XMLHttpRequest, textStatus) {
						msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："
								+ textStatus, 'error');
					}
				});
			}
		}});
	}
	
	</script>